#! /usr/bin/env python
#coding=utf-8
import os
import sys
import py7zr

def unzip_7z(src_path, dst_path='.\\', pwd=''):
    # 检查是否存在
    if os.path.exists(src_path) == True or os.path.isfile(src_path) == True:
        with py7zr.SevenZipFile(src_path, mode='r', password=pwd) as z:
            z.extractall(path=dst_path)
            print('{} is unzip finish'.format(dst_path))
    else:
        print('{} is not exits, please check file path'.format(src_path))
        sys.exit(-1)

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print('Param Empty')
        sys.exit(-1)

    # 获取当前路径
    print('Run 7z-unzip Application')
    for i in range(0, len(sys.argv)):
        print('[input param:{}/{}]{}'.format(i+1, len(sys.argv), sys.argv[i]))

    if len(sys.argv) == 3:
        unzip_7z(sys.argv[1], sys.argv[2])
    else:
        unzip_7z(sys.argv[1], sys.argv[2], sys.argv[3])
